home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / satelite / msat09.tgz / XAWUTILS.C < prev    next >
Text File  |  1994-09-17  |  5KB  |  195 lines

  1. /*
  2.  *   Copyright 1992, 1993, 1994 John Melton (G0ORX/N6LYT)
  3.  *              All Rights Reserved
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 1, or (at your option)
  8.  *   any later version.
  9.  *
  10.  *   This program is distributed in the hope that it will be useful,
  11.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *   GNU General Public License for more details.
  14.  *
  15.  *   You should have received a copy of the GNU General Public License
  16.  *   along with this program; if not, write to the Free Software
  17.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  */
  20.  
  21. /*
  22.     xawutils.c
  23.  
  24.     Prepare a PacSat message for uploading
  25.  
  26.     John Melton
  27.     G0ORX, N6LYT
  28.  
  29.     4 Charlwoods Close
  30.     Copthorne
  31.     West Sussex
  32.     RH10 3QZ
  33.     England
  34.  
  35.     INTERNET:    g0orx@amsat.org
  36.             n6lyt@amsat.org
  37.             john@images.demon.co.uk
  38.             J.D.Melton@slh0613.icl.wins.co.uk
  39.  
  40.     History:
  41.  
  42.     0.1    initial version.
  43.     0.2    fixed file length in header.
  44.     0.3    converted to Xaw.
  45. */
  46.  
  47. #include <X11/Intrinsic.h>
  48. #include <X11/StringDefs.h>
  49. #include <X11/Shell.h>
  50. #include <X11/Xaw/Cardinals.h>
  51. #include <X11/Xaw/Form.h>
  52. #include <X11/Xaw/Label.h>
  53. #include <X11/Xaw/Command.h>
  54. #include <X11/Xaw/SimpleMenu.h>
  55. #include <X11/Xaw/SmeBSB.h>
  56.  
  57. #include "xawutils.h"
  58.  
  59. extern Display *dpy;
  60. extern XtAppContext app_context;
  61. extern Widget compwindow;
  62.  
  63. static Widget shell, form, label, button;
  64.  
  65. static int Ok;
  66.  
  67. static Arg shell_args[] =
  68. {
  69.     {XtNtitle,        (XtArgVal)NULL},
  70.     {XtNheight,        (XtArgVal)80},
  71.     {XtNwidth,        (XtArgVal)350}
  72. };
  73.  
  74. static Arg form_args[] =
  75. {
  76.     {XtNdefaultDistance,    (XtArgVal)0},
  77. };
  78.  
  79. static Arg label_args[] =
  80. {
  81.     {XtNfont,        (XtArgVal)NULL},
  82.     {XtNwidth,        (XtArgVal)350},
  83.     {XtNjustify,        XtJustifyCenter},
  84.     {XtNresize,        False},
  85.     {XtNborderWidth,    (XtArgVal)0},
  86.     {XtNvertDistance,    (XtArgVal)10},
  87.     {XtNtop,        XtChainTop},
  88.     {XtNbottom,        XtChainTop},
  89.     {XtNleft,        XtChainLeft},
  90.     {XtNright,        XtChainLeft}
  91. };
  92.  
  93. static Arg button_args[] =
  94. {
  95.     {XtNcallback,        (XtArgVal)NULL},
  96.     {XtNlabel,        (XtArgVal)NULL},
  97.     {XtNfont,        (XtArgVal)NULL},
  98.     {XtNfromVert,        (XtArgVal)NULL},
  99.     {XtNresize,        (XtArgVal)False},
  100.     {XtNhorizDistance,    (XtArgVal)160},
  101.     {XtNvertDistance,    (XtArgVal)20},
  102.     {XtNtop,        XtChainTop},
  103.     {XtNbottom,        XtChainTop},
  104.     {XtNleft,        XtChainLeft},
  105.     {XtNright,        XtChainLeft}
  106. };
  107.  
  108. static Arg menu_item_args[] =
  109. {
  110.     {XtNlabel,        (XtArgVal)NULL},
  111.     {XtNfont,        (XtArgVal)NULL}
  112. };
  113.  
  114. static void OkCb(Widget w, XtPointer closure, XtPointer data)
  115. {
  116.     XtPopdown(shell);
  117.     
  118.     Ok = TRUE;
  119. }
  120.  
  121. void MessageBox(char *message)
  122. {
  123.     XEvent e;
  124.     Window root, child;
  125.     int x, y, x_win, y_win;
  126.     Dimension width, height;
  127.     unsigned int mask;
  128.     
  129.     Ok = FALSE;
  130.  
  131.     XtVaSetValues(label, XtNlabel, message, NULL);
  132.  
  133.     XQueryPointer(dpy, DefaultRootWindow(dpy), &root, &child, &x, &y,
  134.         &x_win, &y_win, &mask);
  135.     XtVaGetValues(shell, XtNwidth, &width, XtNheight, &height, NULL);
  136.     x -= width / 2;
  137.     y -= height / 2;
  138.     XtVaSetValues(shell, XtNx, (XtArgVal)x, XtNy, (XtArgVal)y, NULL);
  139.  
  140.     XtPopup(shell, XtGrabExclusive);
  141.     
  142.     do
  143.     {
  144.         XtAppNextEvent(app_context, &e);
  145.         XtDispatchEvent(&e);
  146.     }
  147.     while (!Ok);
  148. }
  149.  
  150. void createMessagePopup(XFontStruct *label_font, XFontStruct *button_font)
  151. {
  152.     static XtCallbackRec callback[2];
  153.  
  154.     shell = XtCreatePopupShell("message", transientShellWidgetClass,
  155.                 compwindow, shell_args, XtNumber(shell_args));
  156.  
  157.     form = XtCreateManagedWidget("form", formWidgetClass,
  158.                 shell, form_args, XtNumber(form_args));
  159.  
  160.     label_args[0].value = (XtArgVal)label_font;
  161.     label = XtCreateManagedWidget("label", labelWidgetClass,
  162.                 form, label_args, XtNumber(label_args));
  163.  
  164.     callback[0].callback = OkCb;
  165.     callback[0].closure  = shell;
  166.     button_args[0].value = (XtArgVal)callback;
  167.     button_args[1].value = (XtArgVal)"OK";
  168.     button_args[2].value = (XtArgVal)button_font;
  169.     button_args[3].value = (XtArgVal)label;
  170.     button = XtCreateManagedWidget("button", commandWidgetClass,
  171.                 form, button_args, XtNumber(button_args));
  172.  
  173.     XtRealizeWidget(shell);
  174. }
  175.  
  176. void createMenuPopup(Widget w, XFontStruct *font, MenuEntry *Entry, Cardinal n, XtCallbackProc callback)
  177. {
  178.     Widget shell, entries[20];
  179.     int i;
  180.  
  181.     shell = XtCreatePopupShell("menu", simpleMenuWidgetClass, w, NULL, 0);
  182.  
  183.     for (i = 0; i < n; i++)
  184.     {
  185.         menu_item_args[0].value = (XtArgVal)Entry[i].Label;
  186.         menu_item_args[1].value = (XtArgVal)font;
  187.  
  188.         entries[i] = XtCreateManagedWidget(Entry[i].widgetname, smeBSBObjectClass,
  189.                     shell, menu_item_args, XtNumber(menu_item_args));
  190.  
  191.         XtAddCallback(entries[i], XtNcallback, callback, (XtPointer)Entry[i].Value);
  192.     }
  193. }
  194.  
  195.